package com.newtribe.rmi.rmiservice;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.rmi.Naming;
import java.rmi.Remote;

import com.newtribe.security.cert.CAConfig;
import com.newtribe.security.remote.WorkerInstanceRemote;
import com.newtribe.security.util.FilePathUtil;

/**
 * <p>Title: ҵ��䶯��Ϣ����</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: ShenYang Neusoft Corp.</p>
 * @author fuwei ,fuw@neusoft.com
 * @version 1.0
 */

public class testClient {
  public testClient() {
  }

   public void test() throws Exception  {
     testClient testClient1 = new testClient();

     try {

       String StateQuery ="ca" ;// this.nameResource.getString("statequery");
       Remote rObj =(Remote) Naming.lookup(
           "rmi://localhost:1099/ca");

       WorkerInstanceRemote ms =(WorkerInstanceRemote)rObj ;

       CAConfig ca =  ms.getCaConfig();
       String id =ca.getId() ;
       System.out.println( "--------------" + id);
       
       
       
		String p10File =FilePathUtil.getUserDir()+"/src/designs/csr.csr";

        File f = new File(p10File);
        FileInputStream fis = new FileInputStream(f);
        byte[] req = new byte[(int)f.length()];
        fis.read(req);
        fis.close();
 
        
		byte[]  cert =ms.signCert(new String (req)) ;
       
		FileOutputStream out =new FileOutputStream(FilePathUtil.getUserDir()+"/src/designs/test_p10.cer");
		out.write(cert);
		out.close();
//     long s =    ms.getRunningTime()  ;
//     System.out.println(s +"     :" +s/1000) ;
//
//     ms.startScheduler();

     //ms.stopScheduler();

     }
     catch (Exception ex) {
       ex.printStackTrace();
     }

   }
  public static void main(String[] args) throws Exception {
    new testClient().test() ;

  }

}